﻿using Gridify.WebAPI.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gridify.WebAPI.Data.EntityConfiguration;

public class PersonConfiguration : IEntityTypeConfiguration<Person>
{
    public void Configure(EntityTypeBuilder<Person> builder)
    {
        builder.ToTable("Users");
       
        builder.Property(u => u.Id)
           .IsRequired()
           .HasMaxLength(50);
        
        builder.Property(u => u.UserName)
	        .IsRequired()
	        .HasMaxLength(100);

        builder.Property(u => u.LastName)
           .IsRequired()
           .HasMaxLength(100);

        builder.Property(u => u.FirstName)
           .IsRequired()
           .HasMaxLength(100);
        builder.Property(u => u.Password)
	        .IsRequired()
	        .HasMaxLength(125);
        
        builder.Property(u => u.Age)
           .IsRequired();

        builder.Property(u => u.Email)
           .IsRequired()
           .HasMaxLength(20);
        
        builder.OwnsOne(u => u.Contact, contact =>
        {
	        contact.Property(c => c.PhoneNumber)
		        .HasColumnName("PhoneNumber")
		        .HasMaxLength(20);
	        
	        contact.Property(c => c.Address)
		        .HasColumnName("Address")
		        .HasMaxLength(200);
        });
    }
}
